// forEach  为数组的每个元素都运行一个函数

["Bilbo", "Gandalf", "Nazgul"].forEach(alert);

["Bilbo", "Gandalf", "Nazgul"].forEach((item, index, array) => {
    alert(`${item} is at index ${index} in ${array}`);
});

let users = [
    {id: 1, name: 'John'},
    {id: 2, name: 'Pete'},
    {id: 3, name: 'Mary'}
];

// 找到对象数组中，id值为1的对象
let user = users.find(item => item.id == 1);

alert(user.name);

// filter方法搜索的是所有匹配元素组成的数组
let someUsers = users.filter(item=> item.id < 3);

alert(someUsers.length);